#include "SkyBoxPass.h"
#include "RenderContext.h"

namespace egg{

    SkyBoxPass::SkyBoxPass():MaterialPass(gGPUProgramGroup->getItem("skybox")){
        mWorld2Eye=NumericParamPtr(new NumericParam(GPT_Mat4,"uWorld2Eye"));
        mCenter=NumericParamPtr(new NumericParam(GPT_Vec3,"uCenter"));
        mCubeMap=TextureParamPtr(new TextureParam("uTexture0"));
        bindParam(gGPUParamGroup->mProjectionMatrix);
        bindParam(mWorld2Eye);
        bindParam(mCubeMap);
        bindParam(mCenter);

        mStateCache.mBlendState.mBlend=false;
        mStateCache.mDepthState.mTest=false;
        mStateCache.mDepthState.mWrite=false;
        mStateCache.mStencilState.mTest=false;
        mStateCache.mRastState.mFillMode=GL_FILL;
        mStateCache.mRastState.mCullMode=GL_BACK;
        mStateCache.mRastState.mFrontFace=GL_CCW;
    }

    void SkyBoxPass::_draw(RenderContext& _context,Drawable3D& _drawable){
        mWorld2Eye->set(_context.mCamera->getWorld2EyeMatrix());
        mCenter->set(_context.mCamera->getWorldCenter());
        gDevice->setStateCache(mStateCache);
        this->activate();
        gGeometryGroup->mCube->draw(DM_Triangles);
    }

}